package com.supreme.nettyapp.generalserver.utils;

import com.supreme.nettyapp.generalserver.mqttserver.model.SessionStore;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelStoreUtils {

    public static final Map<String, SessionStore> sessionStoreMap = new ConcurrentHashMap<>();

    public static void putSessionStore(String clientId, SessionStore sessionStore) {
        sessionStoreMap.put(clientId, sessionStore);
    }

    public static SessionStore getSessionStore(String clientId) {
        return sessionStoreMap.get(clientId);
    }

    public static void removeSessionStore(String clientId)  {
        sessionStoreMap.remove(clientId);
    }

    public static void addSessionTopic(String clientId, String topic) {
        sessionStoreMap.get(clientId).getTopics().add(topic);
    }

    public static void removeSessionTopic(String clientId, String topic) {
        sessionStoreMap.get(clientId).getTopics().remove(topic);
    }

    public static boolean containSessionTopic(String clientId, String topic) {
        return sessionStoreMap.get(clientId).getTopics().contains(topic);
    }

    public static void clearSessionTopic(String clientId) {
        sessionStoreMap.get(clientId).getTopics().clear();
    }

    public static void clearSessionStore() {
        sessionStoreMap.clear();
    }
}
